Skip to content

Invalidate irrelevant configuration in node quantization configs#1495

Closed
irenaby wants to merge 3 commits intomainfrom
unset_disabled_quant
Closed

Invalidate irrelevant configuration in node quantization configs#1495
irenaby wants to merge 3 commits intomainfrom
unset_disabled_quant

Conversation

@irenaby
Copy link
Copy Markdown
Contributor

@irenaby irenaby commented Jul 9, 2025

Pull Request Description:

Un-set configuration in node quantization configs if it is or becomes irrelevant. This was we don't hold invalid params, prevent using them by mistake, and removing redundant candidates becomes much easier (given that we don't want to completely restructure the configs at this point). NodeQuantizationConfig removes duplicate candidates automatically.
Replace old tests for nodes configs.

Checklist before requesting a review:

  • I set the appropriate labels on the pull request.
  • I have added/updated the release note draft (if necessary).
  • I have updated the documentation to reflect my changes (if necessary).
  • All function and files are well documented.
  • All function and classes have type hints.
  • There is a licenses in all file.
  • The function and variable names are informative.
  • I have checked for code duplications.
  • I have added new unittest (if necessary).

… quantization configs attributes if quantization is disabled, NodeQuantizationConfig removes duplicates automatically.
@irenaby irenaby force-pushed the unset_disabled_quant branch from c58c921 to e38e426 Compare July 9, 2025 13:11
assert cfg.weights_channels_axis is None


class TestWeightsQuantizationConfig:
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change from here to line 224 (file was moved)

@irenaby irenaby force-pushed the unset_disabled_quant branch from e38e426 to 9c76b53 Compare July 9, 2025 13:54
@irenaby irenaby changed the title Unset disabled quant Invalidate irrelevant configuration in node quantization configs Jul 9, 2025
@irenaby irenaby marked this pull request as ready for review July 9, 2025 14:00
@irenaby irenaby requested a review from elad-c July 9, 2025 14:00

validate: InitVar[bool] = True

def __post_init__(self, validate=True):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can __post_init__ take input arguments?

def _unset(self):
""" Unset activation quantization fields to None. """
self.activation_quantization_method = None
self.activation_n_bits = 0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not None?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There several places where we look for max/min candidate or sort based on nbits whether quantization is enabled or not, which still work with 0 but not with None. I wanted to minimize changes elsewhere and 0 is clearly not a real value. That is the reason, but it's probably not a good enough reason.

return attr_cfg

def set_attr_config(self, attr_name: 'WeightAttrT', attr_qc: WeightsAttrQuantizationConfig):
def set_attr_config(self, attr_name: 'WeightAttrT', attr_qc: WeightsAttrQuantizationConfig, force=False):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typehint

f"Weights attribute {attr_name} could not be found to set parameter {config_parameter_name}.")

attr_cfg = self.get_attr_config(attr_name)
if config_parameter_name == 'enable_weights_quantization':
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can replace str with constant?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a const, it's a name of an attribute in the same class, it's meaningless to define it as const

AttributeQuantizationConfig(
enable_weights_quantization=False)))
enable_weights_quantization=False)),
force=True)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is force needed? Add comment for it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the attribute doesn't exist in the config. Without force it will raise an error. Will add a comment.

WeightsAttrQuantizationConfig(AttributeQuantizationConfig(
enable_weights_quantization=False)))
enable_weights_quantization=False)),
force=True)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same about force

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants